/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-11-27     balanceTWK   first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>

/* defined the LED0 pin: PC0 */
#define LED0_PIN    GET_PIN(B, 5)
void led_entry( void *p);
void thread11_print(void *p);
void thread12_print(void *p);
void thread31_print(void *p);
struct rt_thread led_thread;
struct rt_thread thread11_thread;
struct rt_thread thread12_thread;
struct rt_thread thread31_thread;
int main(void)
{
    int count = 1;
	 rtthread_startup();
	rt_components_init();
    /* set LED0 pin mode to output */
    rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
	rt_thread_init(&led_thread,"led_thread",led_entry,0,1,100);
	rt_thread_startup(&led_thread);
	
	rt_thread_init(&thread12_thread,"thread12",thread12_print,0,1,500);
		rt_thread_startup(&thread12_thread);
	rt_thread_init(&thread11_thread,"thread11",thread11_print,0,1,500);
		rt_thread_startup(&thread11_thread);

	rt_thread_init(&thread31_thread,"thread31",thread31_print,0,3,500);
		rt_thread_startup(&thread31_thread);

    while (count++)
    {

		 rt_schedule();
    }

    return RT_EOK;
}
void led_entry( void *p)
{
	static rt_uint8_t i ;
	if(i++&1)
		rt_pin_write(LED0_PIN, PIN_HIGH);
	else
		rt_pin_write(LED0_PIN, PIN_LOW);
	
	if(i>20 &&i<40)
		rt_thread_delay(500);
}
void thread11_print(void *p)
{
	rt_kprintf("thread1_print-->1\r\n");
}
void thread12_print(void *p)
{
	rt_kprintf("thread1_print-->2\r\n");
}
void thread31_print(void *p)
{
	rt_kprintf("thread3_print-->1\r\n");
}